﻿// <copyright file="ChartLinearScaleTest.cs" company="Oleg V. Polikarpotchkin">
// Copyright © 2008 Oleg V. Polikarpotchkin. All Right Reserved
// </copyright>
// <author>Oleg V. Polikarpotchkin</author>
// <email>ov-p@yandex.ru</email>
// <date>2008-12-25</date>
// <summary>WPF OpenWPFChart library. ChartLinearScale class Test.</summary>
// <revision>$Id$</revision>

using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenWPFChart.Parts;

namespace Tests
{
    /// <summary>
    ///This is a test class for ChartLinearScaleTest and is intended
    ///to contain all ChartLinearScaleTest Unit Tests
    ///</summary>
	[TestClass()]
	public class ChartLinearScaleTest
	{
		#region TestContext
		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}
		#endregion TestContext

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion

		/// <summary>
		/// A test for parametrizied constructor
		///</summary>
		[TestMethod()]
		public void ConstructorTest()
		{
			ChartLinearScale target = new ChartLinearScale(0, 10.0, 300);

			double actual = target.ToPixels(0);
			Assert.AreEqual(0.0, actual);

			actual = target.ToPixels(10.0);
			Assert.AreEqual(300.0, actual);

			target = new ChartLinearScale(10, -10, 300);
			actual = target.ToPixels(-10);
			Assert.AreEqual(300.0, actual);
		}

		#region nearestLongTickTest
		/// <summary>
		/// A test for nearestLongTick
		///</summary>
		[TestMethod()]
		[DeploymentItem("OpenWPFChart.Parts.dll")]
		public void nearestLongTickTest()
		{
			nearestLongTickTestStartLtStop();
			nearestLongTickTestStartGtStop();
		}
		
		/// <summary>
		/// A test for nearestLongTick.
		/// Start &lt; Stop.
		///</summary>
		private void nearestLongTickTestStartLtStop()
		{
			ChartLinearScale_Accessor target = new ChartLinearScale_Accessor()
			{
				Start = -10d,
				Stop = 70d,
				TickStep = 5d
				//LongTickRate = 10 (default)
			};

			// Test with default LongTickAnchor = 0
			double expected = -50d;
			double actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Start
			target.LongTickAnchor = (double)target.Start;
			expected = (double)target.Start;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Stop
			target.LongTickAnchor = (double)target.Stop;
			expected = -30d;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Start + 2
			target.LongTickAnchor = (double)target.Start + 2;
			expected = (double)target.Start + 2 - 50;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);
		}

		/// <summary>
		/// A test for nearestLongTick.
		/// Start &gt; Stop.
		///</summary>
		private void nearestLongTickTestStartGtStop()
		{
			ChartLinearScale_Accessor target = new ChartLinearScale_Accessor()
			{
				Start = 100d,
				Stop = 0d,
				TickStep = 5d
				//LongTickRate = 10 (default)
			};

			// Test with default LongTickAnchor = 0
			target.LongTickAnchor = 0d;
			double expected = (double)target.Start;
			double actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Start
			target.LongTickAnchor = (double)target.Start;
			expected = (double)target.Start;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Stop
			target.LongTickAnchor = (double)target.Stop;
			expected = (double)target.Start;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Start + 2
			target.LongTickAnchor = (double)target.Start + 2;
			expected = (double)target.Start + 2;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Stop + 2
			target.LongTickAnchor = (double)target.Stop + 2;
			expected = (double)target.Start + 2;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);

			// Test with default LongTickAnchor = Stop - 10
			target.LongTickAnchor = (double)target.Stop - 10;
			expected = (double)target.Start + 40;
			actual = target.nearestLongTick();
			Assert.AreEqual(expected, actual);
		}
		#endregion nearestLongTickTest

		/// <summary>
		///A test for Ticks
		///</summary>
		[TestMethod()]
		public void TicksTest()
		{
			ChartLinearScale target = new ChartLinearScale()
			{
				Start = -10d,
				Stop = 70d,
				TickStep = 5d
				//LongTickRate = 10 (default)
			};

			#region Start < Stop
			// Test with default LongTickAnchor = 0
			List<ScaleTick> expected = new List<ScaleTick>()
			{
				new ScaleTick(-10d, false),
				new ScaleTick(-5d, false),
				new ScaleTick(0d, true),
				new ScaleTick(5d, false),
				new ScaleTick(10d, false),
				new ScaleTick(15d, false),
				new ScaleTick(20d, false),
				new ScaleTick(25d, false),
				new ScaleTick(30d, false),
				new ScaleTick(35d, false),
				new ScaleTick(40d, false),
				new ScaleTick(45d, false),
				new ScaleTick(50d, true),
				new ScaleTick(55d, false),
				new ScaleTick(60d, false),
				new ScaleTick(65d, false),
				new ScaleTick(70d, false)
			};
			List<ScaleTick> actual = target.Ticks().ToList<ScaleTick>();
			CollectionAssert.AreEqual(expected, actual);
			#endregion Start < Stop
		}

		/// <summary>
		///A test for ToPixels
		///</summary>
		[TestMethod()]
		public void ToPixelsTest()
		{
			ChartLinearScale target = new ChartLinearScale()
			{
				Start = -10d,
				Stop = 70d,
			};
			double actual = target.ToPixels(-10d);
			Assert.AreEqual(0d, actual);
		}

		/// <summary>
		///A test for FromPixels
		///</summary>
		[TestMethod()]
		public void FromPixelsTest()
		{
			ChartLinearScale target = new ChartLinearScale()
			{
				Start = -10d,
				Stop = 70d,
			};
			double actual = (double)target.FromPixels(0d);
			Assert.AreEqual(-10d, actual);
		}
	}
}
